import { HUAWEI_IOT_URL, project_id } from './const';
import { device_id } from './const';
import http from '@ohos.net.http';
export interface cmdRequest{
    service_id?:string,
    command_name?:string,
    paras:Object
}
export const sendCommand = (cmd:cmdRequest,token:string)=>{
    const httpRequest = http.createHttp()
    return new Promise((resolve,reject)=>{
        httpRequest.request(
            `${HUAWEI_IOT_URL}/v5/iot/${project_id}/devices/${device_id}/commands`
        ,{
            header:{
                "X-Auth-Token":token,
                "Content-Type": "application/json",
            },
            method:http.RequestMethod.POST,
            extraData:cmd
        }).then(resp=>{
            if(resp.responseCode>=200 && resp.responseCode<300){
                resolve(resp.result)
            }else{
                reject(resp)
            }
        })
    })
}